package util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

public class Word4Table {

  public static void main(String[] args) throws IOException {
    // 文档生成方法
    XWPFDocument doc = new XWPFDocument();

    String filePath = "E:\\Desktop\\word4table.docx";
    FileOutputStream out = null; // 创建输出流

    for (int i = 0; i < 3; i++) {
      XWPFTable table = doc.createTable(5, 10);
//      table.setWidthType(TableWidthType.PCT);

      // 获取到刚刚插入的行
      XWPFTableRow row = table.getRow(0);
      // 设置单元格内容
      row.getCell(0).setText("字段名");
      row.getCell(1).setText("字段说明");
      row.getCell(2).setText("数据类型");
      row.getCell(3).setText("长度");
      row.getCell(4).setText("索引");
      row.getCell(5).setText("是否为空");
      row.getCell(6).setText("主键");
      row.getCell(7).setText("外键");
      row.getCell(8).setText("缺省值");
      row.getCell(9).setText("备注");

//            doc.setTable(0, table);
      doc.createParagraph().createRun().addBreak();
    }

    out = new FileOutputStream(new File(filePath), true);
    doc.write(out);

  }
}
